import { IThemeColor } from '../../../../type/index';

interface IData {
  name: string;
  value: number;
}

// valueList[0] 是合格，// valueList[1] 是不合格
export const initRatePie = (echarts: any, dom: HTMLElement, valueList: number[], themeColor: IThemeColor) => {
  let dataList = [] as IData[];
  const labelList = ['成绩合格', '成绩不合格'];

  labelList.forEach((item, index) => {
    dataList.push({
      name: item,
      value: valueList[index],
    });
  });

  const rate = ((valueList[0] / (valueList[0] + valueList[1])) * 100).toFixed(2);

  const charts = echarts.init(dom);
  charts.setOption({
    color: ['#67c23a', '#f56c6c'],
    // color: ['#f96468', '#16a273'],
    title: [
      {
        text: '所有课程成绩合格比例(不包含待录入)',
        textStyle: {
          color: themeColor.font,
          fontSize: 16,
          fontWeight: 'normal',
        },
        padding: [16, 0, 0, 16],
      },
      {
        text: `合格率:\n ${rate}%`,
        textStyle: {
          color: themeColor.font,
          fontSize: 16,
          fontWeight: 'normal',
        },
        top: '48%',
        left: 'center',
      },
    ],
    tooltip: {
      trigger: 'item',
    },
    series: [
      {
        name: '总就业与待就业比例', //用于tooltip
        type: 'pie',
        center: ['50%', '55%'], //调节饼图位置 [x,y]
        radius: ['40%', '70%'],
        minAngle: 6,
        itemStyle: {
          borderRadius: 4,
        },
        label: {
          fontSize: 14,
          color: themeColor.font,
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 16,
            fontWeight: 'bold',
          },
        },
        data: dataList,
      },
    ],
  });
};
